﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _51StringBuilder优化字符串相加
{
    internal class Program
    {
        //特别慢,并且会产生很多垃圾字符串,导致频繁回收垃圾
        private static void Main1(string[] args)
        {
            string str = "";
            for (int i = 0; i < 100000; i++)
            {
                str += i.ToString("d10");
            }
            Console.WriteLine("OK");
            Console.ReadLine();
        }

        //速度块很多,并且节省内存,减少收垃圾的频率
        private static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < 100000; i++)
            {
                sb.Append(i.ToString("d10"));
            }
            string str = sb.ToString();
            Console.WriteLine("OK");
        }
    }
}